<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Абреже</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" type="text/css" href="styles.css"/>

    <?php session_start(); ?>
    <?php

    if ($_POST['first_name'] && $_POST['second_name'] && $_POST['login'] && $_POST['pass'] && $_POST['pass2'] && $_POST['email']) {
        if (strcmp($_POST['first_name'], "") && strcmp($_POST['second_name'], "") && strcmp($_POST['login'], "")
            && strcmp($_POST['pass'], "") && strcmp($_POST['pass2'], "") && strcmp($_POST['email'], "")
        ) {

            if (!strcmp($_POST['pass'], $_POST['pass2'])) {

                $link = mysql_connect('localhost', 'root', 'the1soop');
                mysql_select_db('lectures');
                $login = $_POST['login'];
                $password = $_POST['pass'];
                $first_name = $_POST['first_name'];
                $second_name = $_POST['second_name'];
                $email = $_POST['email'];
                $_POST['not_unique_error'] = !mysql_query("INSERT INTO `user`
                                                                  (login, password, first_name, second_name, email, rating, is_moderator)
                                                           VALUES ('$login', '$password', '$first_name', '$second_name', '$email', 0, false)");

                $_POST['registration_successful'] = true;
                mysql_close($link);
            }
        }
    }

    ?>

    <script>
        function stratchBorders() {
            var s = (document.getElementById('main_content').offsetHeight + 29).toString() + 'px';
            document.getElementById('left_border').style.height = s;
            document.getElementById('right_border').style.height = s;
        }
    </script>
</head>
<body onload="stratchBorders()" onresize="stratchBorders()">
<div id="wrapper">
    <div class="header" style="background-image:url(images/top.jpg)">
        <div style="text-align:right; width:43%; float:left">
            <a href="index.html"><img src="images/logo.png"/></a>
        </div>
        <div style="text-align:left; margin:0 50%; width:35%;">
            <div style="width:100%; height:20px">&nbsp;</div>
            <div class="head_menu_item"><a href="subjects.php">Рубрики</a></div>
            <div class="head_menu_item"><a href="reading_places.php">Лектории&nbsp;</a></div>
            <div class="head_menu_item"><a href="courses.php">Предметы</a></div>
        </div>
    </div>
    <div class="container">
        <div class="content">

            <div class="search_bar">

                <div class="container">
                    <div class="content">
                        <div class="header" style="height:auto">
                            <div class="container">
                                <div class="content">
                                    <div class="decorate_line_search_bar"
                                         style="background-image:url(images/search_bar_top.jpg)">&nbsp;</div>
                                    <!--text-->
                                </div>
                                <!--content-->
                                <div class="decorate_corner_left_search_bar"
                                     style="background-image:url(images/search_bar_corner_top_left.jpg)">&nbsp;</div>
                                <div class="decorate_corner_right_search_bar"
                                     style="background-image:url(images/search_bar_corner_top_right.jpg)">&nbsp;</div>
                            </div>
                            <!--container-->
                        </div>
                        <!--header-->

                        <div class="container">
                            <div class="content">
                                <div class="text" style="height:25px; text-overflow: ellipsis; overflow: hidden;">
                                    <div style="height:3px">&nbsp;</div>
                                    <div style="float:left;">
                                        <form action="">
                                            <input type="text" size="40" id="name" class="input"/>
                                            <input type="submit" value="Поиск" class="button"/>
                                        </form>
                                    </div>
                                    <div style="text-align:left; margin:0 65%; width:35%;">
                                        <div style="border-left:thick#000; width:auto; margin:0 0; text-align:right;">

                                            <div class="head_menu_item">
                                                <a href="signin.php" style="font-size:16px">
                                                    <? if (isset($_SESSION['uid'])) {
                                                    echo $_SESSION['uid'];
                                                } else {
                                                    echo "Вход";
                                                } ?>
                                                </a>
                                            </div>
                                            <div class="head_menu_item"><a href="registration.php"
                                                                           style="font-size:16px">Регистрация</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!--text-->
                            </div>
                            <!--content-->
                            <div class="left" style="height:26px; background-image:url(images/search_bar_left.jpg)">
                                &nbsp;</div>
                            <div class="right" style="height:26px; background-image:url(images/search_bar_right.jpg)">
                                &nbsp;</div>
                            <div class="clear"></div>
                        </div>

                        <div class="footer" style="height:auto">
                            <div class="container">
                                <div class="content">
                                    <div class="decorate_line_search_bar"
                                         style="background-image:url(images/search_bar_bottom.jpg)">&nbsp;</div>
                                    <!--text-->
                                </div>
                                <!--content-->
                                <div class="decorate_corner_left_search_bar"
                                     style="background-image:url(images/search_bar_corner_bottom_left.jpg)">&nbsp;</div>
                                <div class="decorate_corner_right_search_bar"
                                     style="background-image:url(images/search_bar_corner_bottom_right.jpg)">&nbsp;</div
                                        >
                            </div>
                            <!--container-->
                        </div>
                        <!--footer-->
                    </div>
                    <!--content-->
                </div>
                <!--container-->

            </div>
            <!--search_bar-->

            <div class="text">
                <div class="header">
                    <div class="container">
                        <div class="content">
                            <div class="decorate_line" style="background-image:url(images/content_top.jpg)">&nbsp;</div>
                            <!--text-->
                        </div>
                        <!--content-->
                        <div class="decorate_corner_left" style="background-image:url(images/corner_up_left.jpg)">
                            &nbsp;</div>
                        <div class="decorate_corner_right" style="background-image:url(images/corner_up_right.jpg)">
                            &nbsp;</div>

                    </div>
                    <!--container-->
                </div>
                <!--header-->
                <div class="container">
                    <div class="content">
                        <div class="text" id="main_content">
                            <h1>Регистрация</h1>
                            <h2>Заполните, пожалуйста, форму регистрации</h2>

                            <? if (!$_POST['first_name'] || !$_POST['second_name'] || !$_POST['login'] || !$_POST['pass'] || !$_POST['pass2'] || !$_POST['email']) { ?>
                            <p style="margin-left:35px;">All fields must be completed</p>
                            <?
                        } else if (!strcmp($_POST['first_name'], "") || !strcmp($_POST['second_name'], "") || !strcmp($_POST['login'], "")
                            || !strcmp($_POST['pass'], "") || !strcmp($_POST['pass2'], "") || !strcmp($_POST['email'], "")
                        ) {
                            ?>
                            <p style="color: red; margin-left:35px;">All fields must be completed</p>
                            <? } else if (strcmp($_POST['pass'], $_POST['pass2'])) { ?>
                            <p style='color: red; margin-left:35px;'>Passwords are not same</p>
                            <? } else if ($_POST['not_unique_error']) { ?>
                            <p style='color: red; margin-left:35px;'>Login is currently in use</p>
                            <? } else { ?>
                            <p style="margin-left:35px;">Registration successful! Thank you for the registration.</p>
                            <?
                        } ?>

                            <? if (!$_POST['registration_successful'] || ($_POST['not_unique_error'] && $_POST['registration_successful'])) { ?>
                            <form method="post" target="" style="margin-left:35px;">
                                Login:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" size="12"
                                                                                             maxlength="12" name="login"
                                                                                             value="<?$_POST['login']?>"><br/>
                                Password:&nbsp;&nbsp;&nbsp;<input type="password" size="12" maxlength="12" name="pass"
                                                                  value="<?$_POST['pass']?>"><br/>
                                Confirm:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="password" size="12" maxlength="12"
                                                                             name="pass2"
                                                                             value="<?$_POST['pass2']?>"><br/>
                                Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" size="12"
                                                                                                   maxlength="12"
                                                                                                   name="email"
                                                                                                   value="<?$_POST['email']?>"><br/>
                                First Name:&nbsp;<input type="text" size="12" maxlength="12" name="first_name"
                                                        value="<?$_POST['first_name']?>"><br/>
                                Last Name:&nbsp;<input type="text" size="12" maxlength="36" name="second_name"
                                                       value="<?$_POST['second_name']?>"><br/>
                                <input type="submit" title="ОК">
                            </form>
                            <? } ?>
                        </div>
                        <!--text-->
                    </div>
                    <!--content-->
                    <div class="left" id="left_border" style="background-image:url(images/content_left.jpg)">
                        &nbsp;</div>
                    <div class="right" id="right_border" style="background-image:url(images/content_right.jpg)">
                        &nbsp;</div>
                    <div class="clear"></div>
                </div>
                <!--container-->
                <div class="footer" style="height:auto">
                    <div class="container">
                        <div class="content">
                            <div class="decorate_line" style="background-image:url(images/content_bottom.jpg)">
                                &nbsp;</div>
                            <!--text-->
                        </div>
                        <!--content-->
                        <div class="decorate_corner_left" style="background-image:url(images/corner_bottom_left.jpg)">
                            &nbsp;</div>
                        <div class="decorate_corner_right" style="background-image:url(images/corner_bottom_right.jpg)">
                            &nbsp;</div>

                    </div>
                    <!--container-->
                </div>
                <!--footer-->
            </div>
            <!--text-->
        </div>
        <!--content-->
        <div class="clear"></div>
    </div>
    <!--container-->
    <div class="footer" style="background-image:url(images/foot.jpg)"></div>
</div>
<!--warapper-->
<div style="text-indent: -9999px;">
</div>
</body>
</html>